﻿using System.Drawing;

namespace Overload.Phases
{
    public class PlacementPhase
    {
        private readonly World world;

        public PlacementPhase(World world)
        {
            this.world = world;
        }

        public void PlaceUnit(Unit unit, Point worldLocation)
        {
            Point asArray = World.HexToArray(worldLocation);

            if(unit.HasBeenPlaced)
                throw new UnitAlreadyPlacedException(unit);

            if (world.WithinWorldBounds(worldLocation) && (asArray.X == 0 || asArray.X == world.Width - 1))
            {
                unit.WorldLocation = worldLocation;
                unit.HasBeenPlaced = true;
            } 
            else
                throw new InvalidLocationException(worldLocation);
        }
    }
}
